﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinFormsDemoApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void customerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.customerBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.syncSampleDataSet);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'syncSampleDataSet.Customer' table. You can move, or remove it, as needed.
            this.customerTableAdapter.Fill(this.syncSampleDataSet.Customer);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            // Call SyncAgent.Synchronize() to initiate the synchronization process.
            // Synchronization only updates the local database, not your project's data source.
            FxSampleDataCacheSyncAgent syncAgent = new FxSampleDataCacheSyncAgent();
            Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();


            string syncStatsStr = "";
            syncStatsStr += "DownloadChangesApplied =" + syncStats.DownloadChangesApplied.ToString() + Environment.NewLine;
            syncStatsStr += "DownloadChangesFailed =" + syncStats.DownloadChangesFailed.ToString() + Environment.NewLine;
            syncStatsStr += "TotalChangesDownloaded =" + syncStats.TotalChangesDownloaded.ToString() + Environment.NewLine;
            syncStatsStr += "TotalChangesUploaded =" + syncStats.TotalChangesUploaded.ToString() + Environment.NewLine;
            syncStatsStr += "UploadChangesApplied =" + syncStats.UploadChangesApplied.ToString() + Environment.NewLine;
            syncStatsStr += "UploadChangesFailed =" + syncStats.UploadChangesFailed.ToString() + Environment.NewLine;
            syncStatsStr += "SyncStartTime =" + syncStats.SyncStartTime.ToString() + Environment.NewLine;
            syncStatsStr += "SyncCompleteTime =" + syncStats.SyncCompleteTime.ToString() + Environment.NewLine;

            MessageBox.Show(syncStatsStr);

            // TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
            this.syncSampleDataSet.Customer.Merge(this.customerTableAdapter.GetData());
        }
    }
}
